package com.adinall.dsp.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Service;

import com.adinall.dsp.core.utils.CheckUtils;
import com.adinall.dsp.service.AccountService;
import com.cloudcross.ssp.base.dao.GenericIBatisDao;
import com.cloudcross.ssp.model.Account;

/**
 * 
 * 账户用Service
 * 
 * @author 高万超
 * @version V1.0.0 $ 2017年9月8日 下午5:20:27
 */
@Service
public class AccountServiceImpl implements AccountService {

    @Autowired
    private GenericIBatisDao dao;

    public Account getSessionUser() {

        String username = "";
        Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        if (principal instanceof UserDetails) {
            username = ((UserDetails) principal).getUsername();
        } else {
            username = principal.toString();
        }

        if (CheckUtils.isEmpty(username)) {
            return null;
        }
        return dao.get("accountSqlMapper.getByName", username);
    }
}
